import * as resume from '@/api/resume.js'
import {
	baseURL
} from '@/common/config.js'
export default {
	name: 'Experience',
	data() {
		return {
			date: '2020-06-01',
			form: {
				id: '',
				company: '',
				position: '',
				start_time: '请选择',
				up_time: '请选择',
				is_today: false,
				txt: '',
				image_list: [],
				type_text: '',
				type_ids: '',
				spec_index: -1,
				spec: {
					len: 0,
					width: 0,
					height: 0,
					area:0,
					hour: 0,
					weight: 0
				}
			},
			name_null: false,
			position_null: false,
			date_null: false,
			txt_null: false,
			update_null: false,
			deleteShow: false,
			spec_arr: [
				{
					"id": 1,
					"title": "尺寸"
				},
				{
					"id": 2,
					"title": "重量"
				},
				{
					"id": 3,
					"title": "面积"
				},
				{
					"id": 4,
					"title": "时长"
				}
			]
		}
	},
	onLoad(params) {
		if (params.item) {
			this.getMemberResumeExperienceList(JSON.parse(params.item))
		}
		uni.$on('name',(data)=>{
			let arr = []
			let arrID = []
			data.forEach(item=>{
				arr.push(item.title)
				arrID.push(item.id)
			})
			this.form.type_text = arr.join(',')
			this.form.type_ids = arrID.join(',')
		})
		// if(params.id) {
		// 	this.deleteShow = true
		// 	this.form.id = params.id
		// 	this.getMemberResumeExperienceList()
		// }
	},
	onLaunch() {

	},
	methods: {
		//案例复制
		getMemberResumeExperienceList(res) {
			this.form.id = res.id
			this.form.txt = res.txt
			this.form.position = res.position
			this.form.image_list = res.image_list
			this.form.type_ids = res.type_ids
			this.form.type_text = res.type_text
			this.form.start_time = res.start_time_text
			this.form.up_time = res.up_time_text
			this.form.company = res.company
			this.deleteShow = true
			if (res.is_today == 0) {
				this.form.is_today = false
			} else {
				this.form.is_today = true
			}
			// this.form.is_today = res.is_today
		},
		//服务技能跳转
		jumpclassification(){
			this.$tools.navigate('/pages/resume/classification/index')
		},
		PickerSpec(e){
			const id = e.detail.value
			this.form.spec_index = e.detail.value
			if(id == 0){
				
			}
		},
		// checkIndex(index) {
		// 	this.typeIndex = index
		// },
		//至今滑块
		switchChange(e) {
			this.form.is_today = e.detail.value
		},
		//入职时间
		DateChange(e) {
			this.form.start_time = e.detail.value
		},
		//离职时间
		DateChangeup(e) {
			this.form.up_time = e.detail.value
		},
		// 删除按钮
		deleteBnt() {
			let that = this
			uni.showModal({
				title: '提示',
				content: '确定删除该经历吗?',
				success: (res) => {
					if (res.confirm) {
						resume.delMemberResumeExperience({
							id: that.form.id
						}).then(res => {
							uni.navigateBack({
								data: 1
							})
						})

					}
				}
			})
		},
		// 上传图片
		addImgebnt() {
			this.isBusiness = false
			let _this = this
			uni.chooseImage({
				success: (chooseImageRes) => {
					const tempFilePaths = chooseImageRes.tempFilePaths;
					uni.uploadFile({
						url: baseURL + 'zp_common_v1/upload',
						filePath: tempFilePaths[0],
						name: 'file',
						header: {
							//#ifdef APP-PLUS
							'type': 1,
							//#endif
							'Content-type': 'application/json',
							'token': uni.getStorageSync('token')
						},
						success: (uploadFileRes) => {
							let res = JSON.parse(uploadFileRes.data)
							if(res.code == 1){
								_this.form.image_list.push(res.data.fullurl)
							}
							
						}
					});
				}
			});
		},
		delImgebnt(index){
			let _this = this
			uni.showModal({
				title: "删除提示",
				content: "确认删除图片",
				success(e) {
					if(e.confirm){
						_this.form.image_list.splice(index, 1)
					}
				}
			})
		},
		//保存按钮
		ok_form() {
			var that = this
			if (that.form.company == '') {
				that.name_null = true;
				console.log(that.name_null)
				uni.$u.toast('请输入案例名称');
				return
			}
			if (that.form.start_time == '请选择') {
				that.date_null = true;
				uni.$u.toast('请选择设计时间');
				return;
			}
			if (that.form.txt == '') {
				that.txt_null = true;
				uni.$u.toast('请输入案例介绍');
				return;
			}
			resume.editMemberResumeExperience(that.form).then(res => {
				this.$tools.succend('保存成功!')
				setTimeout(res => {
					uni.navigateBack({
						data: 1
					})
				}, 500)
			})
		}
	}
}